package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.factories.ReferenceModifier;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;


import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.*;


@Entity
@NamedQuery(name = "DiagnosticImage.findAll", query = "select o from DiagnosticImage o")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("DGIMG")
public class DiagnosticImage extends Observation implements Serializable {
    
//    public CE SubjectOrientationCode;
    
    public DiagnosticImage() throws Hl7Exception {
    }
    
    
    public void setSubjectOrientationCode(CE ce) {
    	 if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
         {
             setRimCoreActCdSets(ce, DGSUBORIENTATIONCDSETCODE);
         }
         else
         {
             this.setDgSubOrientationCodeEtsId(ce.code().toString());
         }
    }

    public CE getSubjectOrientationCode() throws Hl7Exception {
    	if (this.getDgSubOrientationCodeEtsId().equals(DGSUBORIENTATIONCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getDgSubOrientationCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getDgSubOrientationCodeEtsId()); 
    	return null;  
    }
   
    //DiagnosticImage    
        @Column(name = "DG_SUB_ORIENTATION_CODE_ETS_ID")    
        protected String dgSubOrientationCodeEtsId = DGSUBORIENTATIONCDSETCODE.toString();
        
    protected String getDgSubOrientationCodeEtsId() {
        return dgSubOrientationCodeEtsId;
    }

    protected void setDgSubOrientationCodeEtsId(String dgSubOrientationCodeEtsId) {
        this.dgSubOrientationCodeEtsId = dgSubOrientationCodeEtsId;
    }


}
